package me.zhengjie.business.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.business.domain.sup.Gsgl;
import me.zhengjie.business.service.GeneralQueryService;
import me.zhengjie.business.service.GsglService;
import me.zhengjie.business.service.dto.GeneralQueryCriteria;
import me.zhengjie.business.service.dto.ZhsqQueryCriteria;
import me.zhengjie.utils.DateTimeUtil;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.SecurityUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @website https://el-admin.vip
 * @author xiahongbo
 * @date 2023-08-12
 **/
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "机构照护申请管理")
@RequestMapping("/api/zhsqQuery")
public class ZhsqQueryController {
    private final GeneralQueryService generalQueryService;
    private final GsglService gsglService;

    @GetMapping(value = "/querOrgZhsqxx")
    @ApiOperation("查询机构的照护申请")
    public ResponseEntity<Object> querOrgZhsqxx(GeneralQueryCriteria criteria,
                                                @RequestParam(defaultValue = "0")Integer page,
                                                @RequestParam(defaultValue = "10")Integer size) {

        Long userid = SecurityUtils.getCurrentUserId();
        Gsgl gsgl = gsglService.queryGsgl(userid);
        criteria.setDdbm(gsgl.getBisGsglYljgdm());
        criteria.setZhlb("01");

        List<String> list = new ArrayList<>();
        list.add("00");
        list.add("01");
        list.add("02");
        list.add("03");
        list.add("04");
        list.add("54");
        list.add("55");
        criteria.setZtList(list);
        criteria.setInZt("true");

        int[] startEnd = PageUtil.transToStartEnd(page, size);

        return new ResponseEntity<>(generalQueryService.queryCommonZhxx(criteria, startEnd), HttpStatus.OK);
    }



    @GetMapping(value = "/querOrgYfhZhsqxx")
    @ApiOperation("查询机构的已复核照护申请")
    public ResponseEntity<Object> querOrgYfhZhsqxx(GeneralQueryCriteria criteria,
                                                @RequestParam(defaultValue = "0")Integer page,
                                                @RequestParam(defaultValue = "10")Integer size) {

        Long userid = SecurityUtils.getCurrentUserId();
        Gsgl gsgl = gsglService.queryGsgl(userid);
        criteria.setDdbm(gsgl.getBisGsglYljgdm());
        criteria.setZhlb("01");

        List<String> list = new ArrayList<>();
        list.add("05");
        criteria.setZtList(list);
        criteria.setInZt("true");

        int[] startEnd = PageUtil.transToStartEnd(page, size);

        return new ResponseEntity<>(generalQueryService.queryCommonZhxx(criteria, startEnd), HttpStatus.OK);
    }

    @GetMapping(value = "/querOrgYthZhsqxx")
    @ApiOperation("查询机构的已退回照护申请")
    public ResponseEntity<Object> querOrgYthZhsqxx(GeneralQueryCriteria criteria,
                                                   @RequestParam(defaultValue = "0")Integer page,
                                                   @RequestParam(defaultValue = "10")Integer size) {

        Long userid = SecurityUtils.getCurrentUserId();
        Gsgl gsgl = gsglService.queryGsgl(userid);
        criteria.setDdbm(gsgl.getBisGsglYljgdm());
        criteria.setZhlb("01");

        List<String> list = new ArrayList<>();
        list.add("80");
        criteria.setZtList(list);
        criteria.setInZt("true");

        int[] startEnd = PageUtil.transToStartEnd(page, size);

        return new ResponseEntity<>(generalQueryService.queryCommonZhxx(criteria, startEnd), HttpStatus.OK);
    }

    @GetMapping(value = "/querOrgYgqZhsqxx")
    @ApiOperation("查询机构的已过期照护申请")
    public ResponseEntity<Object> querOrgYgqZhsqxx(GeneralQueryCriteria criteria,
                                                   @RequestParam(defaultValue = "0")Integer page,
                                                   @RequestParam(defaultValue = "10")Integer size) {

        Long userid = SecurityUtils.getCurrentUserId();
        Gsgl gsgl = gsglService.queryGsgl(userid);
        criteria.setDdbm(gsgl.getBisGsglYljgdm());
        criteria.setZhlb("01");

        List<String> list = new ArrayList<>();
        list.add("90");
        criteria.setZtList(list);
        criteria.setInZt("true");

        int[] startEnd = PageUtil.transToStartEnd(page, size);

        return new ResponseEntity<>(generalQueryService.queryCommonZhxx(criteria, startEnd), HttpStatus.OK);
    }

    @GetMapping(value = "/querOrgYbhZhsqxx")
    @ApiOperation("查询机构的已驳回照护申请")
    public ResponseEntity<Object> querOrgYbhZhsqxx(GeneralQueryCriteria criteria,
                                                   @RequestParam(defaultValue = "0")Integer page,
                                                   @RequestParam(defaultValue = "10")Integer size) {

        Long userid = SecurityUtils.getCurrentUserId();
        Gsgl gsgl = gsglService.queryGsgl(userid);
        criteria.setDdbm(gsgl.getBisGsglYljgdm());
        criteria.setZhlb("01");

        List<String> list = new ArrayList<>();
        list.add("-4");
        list.add("-5");
        criteria.setZtList(list);
        criteria.setInZt("true");

        int[] startEnd = PageUtil.transToStartEnd(page, size);

        return new ResponseEntity<>(generalQueryService.queryCommonZhxx(criteria, startEnd), HttpStatus.OK);
    }

    @GetMapping(value = "/querOrgJjgqZhsqxx")
    @ApiOperation("查询机构的即将过期照护申请")
    public ResponseEntity<Object> querOrgJjgqZhsqxx(GeneralQueryCriteria criteria,
                                                   @RequestParam(defaultValue = "0")Integer page,
                                                   @RequestParam(defaultValue = "10")Integer size) {

        Long userid = SecurityUtils.getCurrentUserId();
        Gsgl gsgl = gsglService.queryGsgl(userid);
        criteria.setDdbm(gsgl.getBisGsglYljgdm());
        criteria.setZhlb("01");

        List<String> list = new ArrayList<>();
        list.add("05");
        criteria.setZtList(list);
        criteria.setInZt("true");
        criteria.setBisZhsqDyjsrq2(DateTimeUtil.getDateTime(DateTimeUtil.addDays(+5), DateTimeUtil.DEFAULT_DATE_FORMAT));
        criteria.setBisZhsqDyjsrq1(DateTimeUtil.getDateTime(DateTimeUtil.getNow(), DateTimeUtil.DEFAULT_DATE_FORMAT));

        int[] startEnd = PageUtil.transToStartEnd(page, size);

        return new ResponseEntity<>(generalQueryService.queryCommonZhxx(criteria, startEnd), HttpStatus.OK);
    }



    @GetMapping(value = "/queryOrgTransfZhxx")
    @ApiOperation("查询要从机构转院的照护信息")
    public ResponseEntity<Object> queryOrgTransfZhxx(GeneralQueryCriteria criteria,
                                                    @RequestParam(defaultValue = "0")Integer page,
                                                    @RequestParam(defaultValue = "10")Integer size) {

        criteria.setZhlb("01");

        List<String> list = new ArrayList<>();
        list.add("05");
        criteria.setZtList(list);
        criteria.setInZt("true");

        int[] startEnd = PageUtil.transToStartEnd(page, size);

        return new ResponseEntity<>(generalQueryService.queryCommonZhxx(criteria, startEnd), HttpStatus.OK);
    }

    @GetMapping(value = "/queryHomeTransfZhxx")
    @ApiOperation("查询要从居家转院的照护信息")
    public ResponseEntity<Object> queryHomeTransfZhxx(GeneralQueryCriteria criteria,
                                                     @RequestParam(defaultValue = "0")Integer page,
                                                     @RequestParam(defaultValue = "10")Integer size) {

        criteria.setZhlb("03");

        List<String> list = new ArrayList<>();
        list.add("13");
        list.add("12");
        list.add("07");
        list.add("06");
        criteria.setZtList(list);
        criteria.setInZt("true");

        int[] startEnd = PageUtil.transToStartEnd(page, size);

        return new ResponseEntity<>(generalQueryService.queryCommonZhxx(criteria, startEnd), HttpStatus.OK);
    }
}
